package com.translate.web.api.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.NativeWebRequest;

import com.param.impl.IdPageParam;
import com.translate.vo.InvocieRechargeVO;
import com.response.vo.ResponseModel;
import com.controller.base.AbstractCommonController;
import com.translate.web.param.InvocieRechargeUpdateParam;
import com.translate.web.param.InvocieRechargeAddParam;
import com.translate.web.param.contract.IInvocieRechargeAddParam;
import com.translate.entity.InvocieRecharge;
import com.translate.web.service.IInvocieRechargeService;
import com.basic.service.contract.IBaseService;

@RestController
@RequestMapping("invocieRecharge")
public class InvocieRechargeController extends AbstractCommonController<InvocieRecharge, IdPageParam> {
	private IInvocieRechargeService service;

	public InvocieRechargeController(IInvocieRechargeService service) {
		this.service = service;
	}

	protected long setCreateInfo(IInvocieRechargeAddParam param, NativeWebRequest httpServletRequest) {
		long userId = this.getUserId(httpServletRequest);
		param.setUserId((int) userId);
		return userId;
	}




	/**
	 * 添加
	 *
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/add")
	public ResponseModel<Integer> insert(@RequestBody @Validated InvocieRechargeAddParam param,
			NativeWebRequest httpServletRequest) {
		setCreateInfo(param, httpServletRequest);
		InvocieRecharge invocieRecharge = new InvocieRecharge();
		BeanUtils.copyProperties(param, invocieRecharge);
		int id = this.service.insert(invocieRecharge);

		return ResponseModel.<Integer>success(id);
	}

	@Override
	protected IBaseService<InvocieRecharge> getBaseService() {
		return this.service;
	}

	/**
	 * 添加
	 *
	 * @param <V>
	 * @param param
	 * @return
	 */
	@PostMapping("/update")
	public ResponseModel<Integer> update(@Validated @RequestBody InvocieRechargeUpdateParam param,
			HttpServletRequest httpServletRequest) {
		int res = this.service.parseUpdate(param, InvocieRecharge.class);
		return ResponseModel.<Integer>success(res);
	}

	protected <VO> Class<VO> getTarget() {
		return (Class<VO>) InvocieRechargeVO.class;
	}
}
